<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--sweetalert2-->
    <link href="./sweetalert2/dist/sweetalert2.min.css" rel="stylesheet">
    <script src="./sweetalert2/dist/sweetalert2.min.js" type="text/javascript"></script>

</head>
<body>

<!--网路图片资源-->
<!--<img src="https://avatars.githubusercontent.com/u/1825798?v=4">-->



<script>
    
    /*测试接口
    * 
    * {
  "login": "1",
  "id": 1825798,
  "node_id": "MDQ6VXNlcjE4MjU3OTg=",
  "avatar_url": "https://avatars.githubusercontent.com/u/1825798?v=4",
  "gravatar_id": "",
  "url": "https://api.github.com/users/1",
  "html_url": "https://github.com/1",
  "followers_url": "https://api.github.com/users/1/followers",
  "following_url": "https://api.github.com/users/1/following{/other_user}",
  "gists_url": "https://api.github.com/users/1/gists{/gist_id}",
  "starred_url": "https://api.github.com/users/1/starred{/owner}{/repo}",
  "subscriptions_url": "https://api.github.com/users/1/subscriptions",
  "organizations_url": "https://api.github.com/users/1/orgs",
  "repos_url": "https://api.github.com/users/1/repos",
  "events_url": "https://api.github.com/users/1/events{/privacy}",
  "received_events_url": "https://api.github.com/users/1/received_events",
  "type": "User",
  "site_admin": false,
  "name": "Michael",
  "company": null,
  "blog": "",
  "location": "San Francisco, CA",
  "email": null,
  "hireable": null,
  "bio": null,
  "twitter_username": null,
  "public_repos": 3,
  "public_gists": 0,
  "followers": 31,
  "following": 0,
  "created_at": "2012-06-07T06:10:07Z",
  "updated_at": "2021-09-25T18:06:21Z"
}
* */
    
    
   var adc= Swal.fire({
        title: '输入编号',
        input: 'text',
        inputAttributes: {
            autocapitalize: 'off'
        },
        showCancelButton: true,
        confirmButtonText: '查找',
        cancelButtonText:'取消',
        showLoaderOnConfirm: true,
        preConfirm: (login) => {               //回调函数
            return fetch("./1.txt")            //发送 ajax请求   返回的是promise 对象
                .then(response => {
                    if (!response.ok) {
                        throw new Error(response.statusText)
                    }
                    return response.json()                                //这个JSON对象   会封装在  swal  对象的 value中
                })
                .catch(error => {
                    Swal.showValidationMessage(
                        `Request failed: ${error}`         //请求异常提示
                    )
                })
        },
        allowOutsideClick: () => !Swal.isLoading()
    })

    console.log(adc)   //  swal对象


       adc.then((result) => {
           console.log(result)
        if (result.isConfirmed) {
            Swal.fire({
                title: `${result.value.login}'s avatar`,      //${}取值
                imageUrl: result.value.avatar_url
            })
        }
    })
    
    
    
    
</script>
</body>
</html>